Skip to content

not push company-capf to company-backends when in grouped backends #4725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EasternLi
Copy link

No description provided.

@smile13241324
Copy link

@yyoncho could you have a look here? Without this fix the yasnippet integration in Spacemacs is broken for many layers.

@miyabinomuratic
Copy link
Contributor

Can someone review this PR? In case you need some details, let me clarify the issue and the new logic proposed by this PR.

The original code intends to add company-capf to company-backends if it doesn't exist in the list. To check the existence of company-capf, equal is used to check each element of company-backends:

(setq-local company-backends (cl-adjoin 'company-capf company-backends :test #'equal)))

However, the use of equal is not appropriate here, because company-backends can contain a sublist as described in https://company-mode.github.io/manual/Backends.html#Grouped-Backends.

For example, if company-capf is included in a grouped backend in company-backends like this:

(setq company-backends '((company-capf :with company-yasnippet)))

the original code fails to detect company-capf inside the sublist and the resulting company-backends has two company-capf like this:

(company-capf (company-capf :with company-yasnippet))

To avoid this issue, the check needs to be done based on type of an element in company-backends: if the element is an atom, check if it is company-capf, if the element is a list, check if campany-capf is a member of the list.

The PR uses the correct logic and I've confirmed that the issue is resolved with it.

@kiennq
Copy link
Member

kiennq commented Jun 21, 2025

The work-around for this is to set lsp-completion-provider to :none and then your company-backends configuration will be kept intact.

@miyabinomuratic
Copy link
Contributor

Thank you for your suggestion, but I still would like to the PR to be merged because:

  1. the original code's assumption that company-backends includes only atoms is incorrect
  2. configuring lsp-completion-provider to :none causes an unwanted side effect: company-mode is not enabled via lsp-mode. When lsp-completion-provider is :none, (company-mode 1) at line 918 is not executed:

lsp-mode/lsp-completion.el

Lines 913 to 919 in 45ab3a8

(cond
((equal lsp-completion-provider :none))
((and (not (equal lsp-completion-provider :none))
(fboundp 'company-mode))
(setq-local company-abort-on-unique-match nil)
(company-mode 1)
(setq-local company-backends (cl-adjoin 'company-capf company-backends :test #'equal)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants